<template>
  <div id="vue3-app" class="vue3-app">
    <!-- 应用头部 -->
    <header class="app-header">
      <div class="header-content">
        <h1 class="app-title">
          <vue-icon />
          Vue3 微前端子应用
        </h1>
        <div class="header-info">
          <a-tag color="green">运行中</a-tag>
          <span class="version">v1.0.0</span>
        </div>
      </div>
    </header>

    <!-- 导航菜单 -->
    <nav class="app-navigation">
      <a-menu 
        mode="horizontal" 
        :selectedKeys="selectedKeys"
        @click="handleMenuClick"
        class="nav-menu"
      >
        <a-menu-item key="home">
          <template #icon>
            <home-outlined />
          </template>
          首页
        </a-menu-item>
        <a-menu-item key="about">
          <template #icon>
            <info-circle-outlined />
          </template>
          关于
        </a-menu-item>
        <a-menu-item key="features">
          <template #icon>
            <star-outlined />
          </template>
          功能展示
        </a-menu-item>
        <a-menu-item key="communication">
          <template #icon>
            <message-outlined />
          </template>
          通信测试
        </a-menu-item>
      </a-menu>
    </nav>

    <!-- 主要内容区域 -->
    <main class="app-main">
      <div class="content-wrapper">
        <router-view v-slot="{ Component }">
          <transition name="fade" mode="out-in">
            <component :is="Component" />
          </transition>
        </router-view>
      </div>
    </main>

    <!-- 页脚 -->
    <footer class="app-footer">
      <p>© 2024 Vue3 微前端子应用 | 基于 Vue 3 + Vite + 乾坤</p>
    </footer>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { 
  HomeOutlined, 
  InfoCircleOutlined, 
  StarOutlined, 
  MessageOutlined 
} from '@ant-design/icons-vue'

// 自定义Vue图标组件
const VueIcon = {
  template: `
    <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
      <path d="M2,3L5,3L12,15L19,3L22,3L12,21L2,3Z" fill="#41b883"/>
    </svg>
  `
}

const route = useRoute()
const router = useRouter()

// 当前选中的菜单项
const selectedKeys = computed(() => [route.name || 'home'])

// 菜单点击处理
const handleMenuClick = ({ key }) => {
  router.push({ name: key })
}
</script>

<style scoped>
.vue3-app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.app-header {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  max-width: 1200px;
  margin: 0 auto;
}

.app-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  color: #2c3e50;
}

.header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.version {
  color: #666;
  font-size: 14px;
}

.app-navigation {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.nav-menu {
  max-width: 1200px;
  margin: 0 auto;
  background: transparent !important;
  border-bottom: none !important;
}

.app-main {
  flex: 1;
  padding: 24px;
}

.content-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  min-height: 500px;
  overflow: hidden;
}

.app-footer {
  background: rgba(0, 0, 0, 0.8);
  color: white;
  text-align: center;
  padding: 16px;
  margin-top: auto;
}

.app-footer p {
  margin: 0;
  opacity: 0.8;
}

/* 路由切换动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    gap: 12px;
    padding: 16px;
  }
  
  .app-title {
    font-size: 20px;
  }
  
  .nav-menu {
    justify-content: center;
  }
  
  .app-main {
    padding: 16px;
  }
}
</style>